package com.parfois.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

public class HomeViewPagerAdapter extends PagerAdapter {
	private List<ImageView> ivlist;
	private List<Bitmap> bmlist;
	private Context context;

	public HomeViewPagerAdapter(Context context,List<ImageView> viewlist,List<Bitmap> bmlist) {
		this.ivlist = viewlist;
		this.bmlist = bmlist;
		this.context = context;
	}
	
	public Object instantiateItem(ViewGroup container, int position) {
		//position%=ivlist.size();
		//container.addView(ivlist.get(position), 0);
		position%= bmlist.size();
		if (position<0){
			//position = ivlist.size()+position;
			position = bmlist.size()+position;
		}
		//return ivlist.get(position);
		ImageView imageView = new ImageView(context);
		imageView.setImageBitmap(bmlist.get(position));
		container.addView(imageView);
		imageView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {

			}
		});
		return imageView;
	}
	
	public void destroyItem(ViewGroup container, int position, Object object) {
		position%=ivlist.size();
		if (position<0){  
            position = ivlist.size()+position;  
        }
		ImageView view = ivlist.get(position);
        container.removeView(view);
	}
	
	public int getCount() {
		return ivlist.size()*100;
	}

	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

}
